package DataBase;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Vector;

public class GetSuppliersForItem {

	private String itemID;

	public GetSuppliersForItem(String itemID) {
		this.itemID = itemID;
	}

	public Vector<Vector> getSuppliers() {
		Vector<Vector> supItems = new Vector<Vector>();

		SQLConnection sc = new SQLConnection();

		try {

			PreparedStatement ps = sc
					.getConnection()
					.prepareStatement(
							"SELECT si.suppItemPrice, s.suppName, si.iid, si.suppId " +
							"FROM  supplier_item si, supplier s " +
							"WHERE si.iid=? AND s.suppID=si.suppId;");
			ps.setString(1, itemID);
			ResultSet rs = ps.executeQuery();

			ResultSetMetaData rsmd = rs.getMetaData();

			while (rs.next()) {

				Vector<String> row = new Vector<String>();
				for (int col = 1; col <= rsmd.getColumnCount(); col++) {
					row.add(rs.getString(col).toString());
				}// for
				supItems.add(row);
			}// while
			ps.close();
			rs.close();
			sc.getConnection().close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return supItems;
	}

}
